package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.core.PageSynchronizer
import io.xxx.omni.oss.sdk.DdClient

/**
 * 当当
 */
// https://open.dangdang.com/home/docs/guide/7
abstract class DdSynchronizer : PageSynchronizer<JsonObject>() {

    protected abstract val method: String

    protected open val v = 1.0

    override fun getResponse(context: Context, pageNo: Int, containsTotal: Boolean): JsonObject {
        val request = buildRequest(context, pageNo)
        val client = applicationContext.getBean(DdClient::class.java)
        val response = client.execute(store, method, request)
        if (response["resultCode"].asString != "0") {
            throwException(context, request, response)
        }
        return response
    }

    protected abstract fun buildRequest(context: Context, pageNo: Int): Map<String, Any>
}